// pages/moxibustion/moxibustion.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        currentValue: 1, // 当前进度
        currentItem: {}, // 当前显示的计划
        timetest: '2024-05-18', // 测试时间
        istest: true,
        userinfo: null,
        total: 0,
        // 我的计划数据
        jihuaDataList: {
            data: [],
            total: 1
        },
        // 测试结果数据
        introductionSymptomsList: [],
        showProp: false, // 弹出层显示
        introductionSymptomsNoew: {}, // 当前点击的弹层显示的数据
        isJinrijihuawancheng: false, // 今日计划是否完成
    },

    onClose() {
        this.setData({
            showProp: false
        })
    },

    // 点击计划item
    clickJiHuaItem(e) {
        console.log('点击计划item1', this.data.currentItem)
        console.log('点击计划item2', e.currentTarget.dataset.item);
        // wx.setStorageSync('jhcurrentItem', this.data.currentItem);
        wx.setStorageSync('jhcurrentItem', e.currentTarget.dataset.item);
        wx.navigateTo({
            url: '../../template/jihua/jihua',
        })
    },

    // 点击添加计划
    addpaln() {
        wx.navigateTo({
            url: '../../template/home/test/viewResults/viewResults',
        })
    },

    // 获取当前计划
    getJiHuaList() {
        const openid = wx.getStorageSync('openid')
        const params = {
            condition: {
                openid,
                sfwc: '未完成'
            },
            current: 1,
            size: 999
        }
        wx.$http.post('/aijiupaln/paged', params).then(({
            data: {
                data
            }
        }) => {
            console.log('获取当前计划', data)
            wx.setStorageSync('jihualistData', data)
            this.setData({
                jihuaDataList: data,
                total: data.total,
                currentItem: data.data[0]
            })
        })
    },

    onDrag(event) {
        this.setData({
            currentValue: event.detail.value,
        });
    },

    // 点击卡片
    clicktestcrrd(e) {
        console.log('e', e.currentTarget.dataset.item)
        this.setData({
            introductionSymptomsNoew: e.currentTarget.dataset.item,
            showProp: true,
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    async onShow() {
        const jihualistData = await wx.getStorageSync('jihualistData')
        console.log('艾灸也没按-----------生命周期函数--监听页面显示', jihualistData)
        this.setData({
            total: jihualistData.length,
            jihuaDataList: jihualistData,
            currentItem: jihualistData[0]
        })
        // ----------每天打开这里刷新更新计划--------------
        const timedaystrbiaoshi = wx.getStorageSync('timedaystrbiaoshi')
        const currentValue = wx.getStorageSync('currentValue')
        const newdate = new Date()
        const jintiantimestr = newdate.getFullYear() + '-' + (newdate.getMonth() + 1) + '-' + newdate.getDate()
        console.log('----------------判断计划已经不是当天最新：', timedaystrbiaoshi == jintiantimestr, timedaystrbiaoshi, jintiantimestr)
        let currentValueNum = 1
        if (timedaystrbiaoshi && timedaystrbiaoshi == jintiantimestr && currentValue) {
            console.log('获取到今天在进行的计划-------', jintiantimestr, currentValue);
            jihualistData.forEach((o, i) => {
                if (o.id == currentValue.id) {
                    currentValueNum = i + 1
                }
            })
            this.setData({
                currentItem: currentValue,
            })
        } else {
            console.log('------------------------刷新计划------------------------');
            console.log('刷新计划------------------------', jintiantimestr);
            wx.setStorageSync('timedaystrbiaoshi', jintiantimestr)
            if (jihualistData.data && jihualistData.length) {
                wx.setStorageSync('currentValue', jihualistData[0])
            }
            wx.setStorageSync('isJinrijihuawancheng', false)
        }
        const isJinrijihuawancheng = wx.getStorageSync('isJinrijihuawancheng')
        this.setData({
            isJinrijihuawancheng,
            currentValue: currentValueNum,
        })
        // ------------
        // this.getJiHuaList();
        const test_defen_params = wx.getStorageSync('test_defen_params')
        const userinfo = wx.getStorageSync('userinfo')
        const introductionSymptomsListtime = wx.getStorageSync('introductionSymptomsListtime')
        
        const introductionSymptomsList = wx.getStorageSync('introductionSymptomsList')
        this.setData({
            userinfo,
            introductionSymptomsList,
            timetest: introductionSymptomsListtime
        })
        console.log('测试得分结果-------', test_defen_params);
        if (test_defen_params) {
            this.setData({
                istest: false
            })
        } else {
            this.setData({
                istest: true
            })
        }
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})